﻿using Repid.Entity.Basic;
using Repid.Core.Aop;
using Repid.MvcExtension;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.Mvc;

namespace Repid.MvcApplication.Areas.Manage.Controllers
{
    public class AuthorizeController : Controller
    {
        [HttpGet]
        public ActionResult Login()
        {
            SessionFactory.LoginOut();
            return View();
        }

        [HttpPost]
        public string Login(string username, string password)
        {
            var result = ServiceFactory.BasicUser.Login(username, password);

            if (result.Success)
            {
                var model = result.Data as BasicUser;

                SessionFactory.UserID = model.ID;
                SessionFactory.UserName = model.UserName;
                SessionFactory.UserRole = "MANAGE";
                SessionFactory.IsSuper = model.IsSuper;
            }

            return result.Serialize();
        }
    }
}